package com.oracle.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyServlet extends HttpServlet {

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("初始化一个serlvet");
    }
    //alt + insert       ctrl+x
//    @Override
//    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
//    }

    //专门用来接收 get请求的
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        System.out.println(username);

        String password = req.getParameter("password");
        System.out.println(password);

        System.out.println("哈哈哈 我是get请求-----请求来了");

        //响应回来
        //resp.sendRedirect("main.html");

        if("曹操".equals(username) && "123".equals(password)){
            //request 对象的转发   登录 是查询操作 , 登录成功后 转发到 别的serlvet
            RequestDispatcher requsetDispatcher = req.getRequestDispatcher("productServlet");
            requsetDispatcher.forward(req,resp); //
        }
    }

    //专门接收 post请求的
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("我是post请求");
    }

    @Override
    public void destroy() {
        System.out.println("销毁");
    }
}
